USE [OctoNetApps]
GO

/****** Object:  StoredProcedure [classified].[ClassifiedAttributes_GetByID]    Script Date: 05/25/2011 07:00:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO






CREATE PROCEDURE [classified].[ClassifiedAttributes_GetByID]
	@CategoryID bigint,
	@AttributeID bigint,
	@MaxAttributeValue int OUTPUT
AS
BEGIN

	SET NOCOUNT ON;
	IF (@AttributeID <> 0)
	BEGIN
		SELECT AttributeValue, AttributeValueName
		FROM classified.ClassifiedAttributeValues
		WHERE  AttributeID = @AttributeID
		ORDER BY AttributeValue
		
		SELECT @MaxAttributeValue = ISNULL(MAX(AttributeValue),0) 
		FROM classified.ClassifiedAttributeValues
		WHERE AttributeID = @AttributeID

		SELECT 
			AttributeTitle,
			AttributeDescription,
			[Required],
			SortOrder,
			IsCustom
		 FROM classified.ClassifiedAttributes
		WHERE CategoryID = @CategoryID AND AttributeID = @AttributeID
		ORDER BY SortOrder
	END
	ELSE
	BEGIN
		SELECT AttributeID, AttributeValue, AttributeValueName
		FROM classified.ClassifiedAttributeValues
		WHERE CategoryID = @CategoryID
		ORDER BY AttributeValue

		SELECT 
			AttributeID,
			AttributeTitle,
			AttributeDescription,
			[Required],
			SortOrder,
			IsCustom
		 FROM classified.ClassifiedAttributes
		WHERE CategoryID = @CategoryID
		ORDER BY SortOrder
	END
END




GO


